// pages/ADaddress/ADaddress.js
import { Address, isLogin } from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['请选择', '请选择', '请选择'],
    code: [],
    user: '',
    phone: '',
    address: '',
  },
  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value,
      code: e.detail.code
    })
  },
  user(e) {
    this.setData({
      user: e.detail.value
    })
  },
  phone(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  address(e) {
    this.setData({
      address: e.detail.value
    })
  },
  add() {
    let token = wx.getStorageSync('token')
    if (token) {
      let phone = this.data.phone
      let address = this.data.address
      let user = this.data.user
      let pro = this.data.code[0] + '000000'
      let city = this.data.code[1] + '000000'
      let dis = this.data.code[2] + '000000'
      Address(`/user/shipping-address/add?address=${address}&cityId=${city}&linkMan=${user}&mobile=${phone}&provinceId=${pro}&token=${token}&districtId=${dis}`).then(res => {
        if (res.msg == 'success') {
          console.log(1)
          wx.reLaunch({
            url: `/pages/address/address`
          });
        }
      })
    } else {
      isLogin()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})